<template>
  <div class="main">
    <div style="width: 100%;height: 40px;background-color: #fff;margin-bottom: 20px;padding: 10px;">当前模块:<span
        style="font-weight: bold;">教学事务信息处理系统的本单位用户（帐号）管理操作 </span> </div>
    <div class="main-body">

      <div class="main-header float-left">
        <!-- <div class="d-flex"> -->
        <el-form :inline="true" :model="formInline" class="demo-form-inline" size="mini">


          <!-- <el-form-item label="单位：" v-if="schoolList.length > 0">
            <el-select v-model="formInline.ddl_bb" placeholder="请选择">
              <el-option v-for="(item, index) in schoolList" :key="index" :label="item.XQJC" :value="item.NEW_XQDM">
              </el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="">
            <el-input v-model="formInline.xm" placeholder="请输入名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit" icon="el-icon-search">查询</el-button>
            <el-button type="primary" @click="onSubmit2" icon="el-icon-plus">新增本系统用户</el-button>
          </el-form-item>
        </el-form>
        <!-- </div> -->
      </div>

      <el-dialog title="用户权限信息的修改与设置窗口" :visible.sync="dialogDetails" width="800px" :before-close="handleClose">

        <div style="width:100%;">
          <div style="color:#fff;width:800px;text-align:center;height:40px;background-color:#ff4d4f;line-height:40px;">
            当前执行新增本系统用户，且分配权限的操作</div>
          <table border='0' cellspacing="0" cellpadding="0"
            style="border-collapse:collapse;border-style:none; font-size:13px; width:100%;margin-top:20px">
            <tr>
              <td style="border:1px solid #3c3c3c; height:33px; text-align:center; width:100px;">
                工作校区
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center; width:200px;">
                <el-select v-model="gzxiaoqu" placeholder="请选择" @change="onChange2">
                  <el-option v-for="(item, index) in schoolList" :key="index" :label="item.XQJC" :value="item.NEW_XQDM">
                  </el-option>
                </el-select>
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center; width:100px;">
                用户姓名
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center; width:200px;">
                <el-select v-model="user" placeholder="请选择" @change="changeJzgname">
                  <el-option v-for="(item) in JzgOptions" :key="item" :label="item.XM" :value="item.TeacherID">
                  </el-option>
                </el-select>
                <!-- <span spanspanID="lb_XXMC" runat="server" Text=""></span> -->
              </td>
            </tr>
            <tr>
              <td style="border:1px solid #3c3c3c; height:33px; text-align:center;">
                用户级别
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center; ">
                <el-radio v-model="userLevel" label="区级">区级</el-radio>
                <el-radio v-model="userLevel" label="校级">校级</el-radio>
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center; ">
                管理校区
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center;">
                <span v-text="TeacherInfo.GZ_XQ"></span>

              </td>
            </tr>
            <tr>
              <td style="border:1px solid #3c3c3c; height:33px; text-align:center;">
                岗位状态
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center; ">
                <span v-text="TeacherInfo.JSZT"></span>

              </td>
              <td style="border:1px solid #3c3c3c; text-align:center; ">
                帐号状态
              </td>
              <td style="border:1px solid #3c3c3c; text-align:center;">
                <span>启用</span>
              </td>
            </tr>
          </table>
        </div>

        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogDetails = false">取 消</el-button>
          <el-button type="primary" @click="adduer">提 交</el-button>
        </span>
      </el-dialog>

      <div class="main-center float-left">
        <el-table :data="tableData" height="650" style="width: 100%;margin-top: 6px;"
          :header-cell-style="{ background: '#fafafa', color: '#000000e0', fontWeight: 600 }">
          <el-table-column type="index" label="序号" width="100"></el-table-column>
          <el-table-column prop="XM" label="用户姓名"></el-table-column>
          <el-table-column prop="Login_ID" label="登录帐号名"></el-table-column>
          <el-table-column prop="GL_XQDM" label="管理校区">
            <template slot-scope="scope">
              <span>{{ formatXiaoqu(scope.row.GL_XQDM) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="Role" label="角色"></el-table-column>
          <el-table-column prop="SYZT" label="帐号状态"></el-table-column>
          <el-table-column prop="GWZT" label="岗位状态"></el-table-column>
          <el-table-column fixed="right" label="详情" width="200">
            <template slot-scope="scope">
              <!-- <el-button @click="handleClick(scope.row)" type="text" size="small"
                style="color: #ff4d4f;" icon="el-icon-view">查看详情</el-button> -->
              <el-button type="text" size="small" style="color: #ff4d4f;" icon="el-icon-delete"
                @click="handleDel(scope.row)">删除</el-button>

              <!-- /el-icon-edit-outline -->
            </template>
          </el-table-column>
        </el-table>

        <!-- <div class="footer-pagination">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="formInline.currentPage" :page-sizes="[10, 20, 30, 50, 100, 200, 300, 500]"
            :page-size="formInline.limit" layout="total, sizes, prev, pager, next, jumper" :total="formInline.total">
          </el-pagination>
        </div> -->
      </div>

    </div>
  </div>
</template>
<script>
import httplogin from "../../api/login";
//getOnGuardFaculty
export default {
  name: 'Social',
  data() {
    return {
      tableData: [],
      userLevel: "校级",
      formInline: {
        benqu: "",
        gzXqdm: '',
        xm: '',
        ddl_xz: '',
        ddl_jdfs: '',
        currentPage: 1,
        limit: 10,
        total: 0
      },
      ddl_lb_list: [
        {
          value: 0,
          label: '本区编内'
        },
        {
          value: 1,
          label: '本区编外'
        },
      ],//类别 options
      ddl_bb_list: [],//办别 options
      ddl_xz_list: [
        {
          value: '全部',
          label: '全部'
        },
        {
          value: '普通',
          label: '普通'
        },
        {
          value: '工读',
          label: '工读'
        },
        {
          value: '特教',
          label: '特教'
        },
      ],//性质 options
      ddl_jdfs_list: [
        {
          value: '全部',
          label: '全部'
        },
        {
          value: '走读',
          label: '走读'
        },
        {
          value: '寄宿',
          label: '寄宿'
        },
      ],//就读方式 options
      dialogDetails: false,
      user: {
        "glXqdm": "",
        "gllx": "",
        "id": 0,
        "jb": "",
        "role": "",
        "userid": ""
      },
      schoolList: [],
      JzgOptions: [],
      TeacherInfo: ""
    }
  },
  mounted() {
    this.getschoolList()
    this.getUserListway()
  },
  methods: {
    async adduer() {
      console.log(this.TeacherInfo)
      var data = {
        glXqdm: this.TeacherInfo.GZ_XQDM,
        jb: this.userLevel,
        userid: this.user,
        gllx: '0'

      }
      var res = await httplogin.saveUserList(data)
      if (res.data.code == 200) {
        this.$message({
          type: 'success',
          message: res.data.msg
        });
        this.getUserListway()
        this.dialogDetails = false
      } else {
        this.$message({
          type: 'success',
          message: res.data.msg
        });
      }
    },
    async getUserListway() {
      let data = {
        page: this.formInline.currentPage,
        size: this.formInline.limit,
        xm: this.formInline.xm
      }
      var res = await httplogin.getJwUser(data);
      if (res.data.code == 200) {
        this.tableData = res.data.data.list;
        // this.formInline.total = res.data.data.total
      }
    },
    onSubmit2() {
      this.dialogDetails = true
    },
    async handleDel(val) {

      var data = {

        userid: val.TeacherId
      }
      var res = await httplogin.removeUerList(data)
      if (res.data.code == 200) {
        this.$message({
          type: 'success',
          message: res.data.msg
        });
        this.getUserListway()
      } else {
        this.$message({
          type: 'success',
          message: res.data.msg
        });
        this.getUserListway()
      }
    },
    formatXiaoqu(val) {
      console.log(val)
      if (val) {
        var obj = this.schoolList.filter((e) => {
          return e.NEW_XXDM == val
        })
        return obj[0].XQJC
      }

    },
    changeJzgname(e) {
      console.log(e)
      var obj = this.JzgOptions.filter((val) => {
        return val.TeacherId = e
      })
      this.TeacherInfo = obj[0]

    },
    async onChange2(e) {
      var data = {
        gzXqdm: e
      }
      var res = await httplogin.getOnGuardFaculty(data);
      if (res.data.code == 200) {
        this.JzgOptions = res.data.data.facultyInfo
      }
    },
    async getschoolList() {
      let res = await httplogin.getUserPermissionInfo();
      if (res.data.code == 200) {
        // if (res.data.data.estate == "区级") {
        this.schoolList = res.data.data.UserPermission
        this.sortPingyinfun(this.schoolList)
        // }
      }
    },
    sortPingyinfun(list) {
      list.sort((a, b) => a.XQJC.localeCompare(b.XQJC))
      return list
    },
    //点击查看详情 open 弹框
    handleClick(row) {
      console.log(row)
      this.dialogDetails = true
    },
    //close 弹框
    handleClose() {
      this.dialogDetails = false
    },
    onSubmit() {
      // console.log(this.formInline);
      this.getUserListway()
    },
    handleSizeChange(val) {
      this.formInline.limit = val
      this.getUserListway()

    },
    handleCurrentChange(val) {
      this.formInline.currentPage = val
      this.getUserListway()
      console.log(`当前页: ${val}`);
    }
  }
}
</script>

<style scoped>
::v-deep .el-dialog__header {
  background-color: #ff4d4f !important;
}

::v-deep .el-dialog__title {
  line-height: 24px;
  font-size: 20px;
  color: #fff !important;
  /* font-weight: 600; */
}

.main {
  width: 100%;
  float: left;
  height: auto;
  box-sizing: border-box;
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #f6f6f6;
  overflow-x: auto;
  overflow-y: auto;
}

.main-body {
  width: 100%;
  height: auto;
  float: left;
  background-color: #fff;
  box-sizing: border-box;
  padding: 18px;
  border-radius: 12px;
}

.float-left {
  width: 100%;
  height: auto;
  float: left;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.d-flex {
  display: flex;
  align-items: center;
}

.mr-24 {
  margin-right: 24px;
}

.fontcolor {
  color: rgba(0, 0, 0, 0.88);
  word-break: break-word;
  line-height: 1.5714285714285714;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  font-size: 14px;
  box-sizing: border-box;
}

.footer-pagination {
  padding: 10px 0 0 0;
  text-align: right;
}

.font-all {
  color: rgba(0, 0, 0, 0.88);
  font-size: 14px;
  line-height: 1.5714285714285714;
  list-style: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  scrollbar-color: rgba(0, 0, 0, 0.25) rgba(5, 5, 5, 0.06);
}
</style>

<style scoped>
::v-deep .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
  flex: 1;
  overflow: auto;
}

.td1 {
  border: 1px solid #8c8c8c;
  height: 40px;
  text-align: center;
  line-height: 40px;
  color: #3c3c3c;
  padding: 3px;
  /* width: 40%; */
}

.inputbox {
  text-align: center;
  line-height: 25px;
  border: 1px solid #b3b3b3;
  font-size: 13px;
  height: 25px;
  width: 96%;
}

.rblList td {
  font-size: 13px;
  color: #3c3c3c;
  border-style: none;
  text-align: left;
  height: 30px;
  line-height: 30px;
}
</style>